
<h1><span class="yiyi-st" id="yiyi-12">numpy.frompyfunc</span></h1>
        <blockquote>
        <p>原文：<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.frompyfunc.html">https://docs.scipy.org/doc/numpy/reference/generated/numpy.frompyfunc.html</a></p>
        <p>译者：<a href="https://github.com/wizardforcel">飞龙</a> <a href="http://usyiyi.cn/">UsyiyiCN</a></p>
        <p>校对：（虚位以待）</p>
        </blockquote>
    
<dl class="function">
<dt id="numpy.frompyfunc"><span class="yiyi-st" id="yiyi-13"> <code class="descclassname">numpy.</code><code class="descname">frompyfunc</code><span class="sig-paren">(</span><em>func</em>, <em>nin</em>, <em>nout</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-14">使用一个任意的Python函数并返回一个Numpy ufunc。</span></p>
<p><span class="yiyi-st" id="yiyi-15">例如，可以用于向内置的Python函数添加广播（参见示例部分）。</span></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field-odd field"><th class="field-name"><span class="yiyi-st" id="yiyi-16">参数：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-17"><strong>func</strong>：Python函数对象</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-18">一个任意的Python函数。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-19"><strong>nin</strong>：int</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-20">输入参数的数量。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-21"><strong>nout</strong>：int</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-22">由<em class="xref py py-obj">func</em>返回的对象数。</span></p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name"><span class="yiyi-st" id="yiyi-23">返回：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-24"><strong>out</strong>：ufunc</span></p>
<blockquote class="last">
<div><p><span class="yiyi-st" id="yiyi-25">返回Numpy通用函数（<code class="docutils literal"><span class="pre">ufunc</span></code>）对象。</span></p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric"><span class="yiyi-st" id="yiyi-26">笔记</span></p>
<p><span class="yiyi-st" id="yiyi-27">返回的ufunc总是返回PyObject数组。</span></p>
<p class="rubric"><span class="yiyi-st" id="yiyi-28">例子</span></p>
<p><span class="yiyi-st" id="yiyi-29">使用frompyfunc将广播添加到Python函数<code class="docutils literal"><span class="pre">oct</span></code>：</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">oct_array</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">frompyfunc</span><span class="p">(</span><span class="nb">oct</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">oct_array</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">((</span><span class="mi">10</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="mi">100</span><span class="p">)))</span>
<span class="go">array([012, 036, 0144], dtype=object)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">((</span><span class="nb">oct</span><span class="p">(</span><span class="mi">10</span><span class="p">),</span> <span class="nb">oct</span><span class="p">(</span><span class="mi">30</span><span class="p">),</span> <span class="nb">oct</span><span class="p">(</span><span class="mi">100</span><span class="p">)))</span> <span class="c1"># for comparison</span>
<span class="go">array([&apos;012&apos;, &apos;036&apos;, &apos;0144&apos;],</span>
<span class="go">      dtype=&apos;|S4&apos;)</span>
</pre></div>
</div>
</dd></dl>
